package threadLearn.producerconsumer.v4;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;


/**
 * 完美的实现了生产者消费者
 * @Description:
 * @author wanglong
 * @createDate: 2019年3月25日 下午5:10:01
 */
public class Client {
	
	public static void main(String[] args) {
		ExecutorService service = Executors.newFixedThreadPool(10);
		
		List<String> basket = new ArrayList<>(10);
		ReentrantLock lock = new ReentrantLock();
		Condition prCondition = lock.newCondition();
		Producer p1 = new Producer(basket, lock, prCondition);
        Producer p2 = new Producer(basket, lock, prCondition);
        Producer p3 = new Producer(basket, lock, prCondition);
        Consumer c1 = new Consumer(basket, lock, prCondition);
        Consumer c2 = new Consumer(basket, lock, prCondition);
        Consumer c3 = new Consumer(basket, lock, prCondition);
        Consumer c4 = new Consumer(basket, lock, prCondition);
        Consumer c5 = new Consumer(basket, lock, prCondition);
        
        
        service.execute(p1);
        service.execute(c1);
        service.execute(c2);
        service.execute(c3);
        service.execute(c4);
        service.execute(c5);
        service.execute(p2);
        service.execute(p3);
}

}
